#include "U8glib.h"
#include <dht11.h>

dht11 DHT11;

#define DHT11PIN 9
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);  // I2C / TWI 
const   uint8_t bitmap_s []   U8G_PROGMEM  ={0x00,0x00,0x00,0x00,0xFD,0xFC,0x04,0x84,0x44,0x84,0x44,0x84,0x28,0x88,0x28,0x88,
0x10,0x50,0x10,0x50,0x28,0x20,0x28,0x20,0x44,0x50,0x44,0x88,0x81,0x04,0x02,0x02};/*"双",0*/

const   uint8_t bitmap_y []   U8G_PROGMEM  ={0x00,0x00,0x27,0xFE,0x14,0x20,0x14,0x40,0x85,0xFC,0x45,0x04,0x45,0xFC,0x15,0x04,
0x15,0xFC,0x25,0x24,0xE4,0x20,0x24,0xA8,0x29,0x24,0x2A,0x22,0x30,0xA0,0x00,0x40};/*"源",1*/

const   uint8_t bitmap_d []   U8G_PROGMEM  ={0x01,0x00,0x01,0x00,0x01,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,
0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x0A,0x01,0x02,0x01,0x02,0x00,0xFE};/*"电",2*/

const   uint8_t bitmap_z[]    U8G_PROGMEM  ={0x00,0x00,0x7F,0xF8,0x00,0x10,0x00,0x20,0x00,0x40,0x01,0x80,0x01,0x00,0xFF,0xFE,
0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x05,0x00,0x02,0x00};/*"子",3*/

void draw(void) {
  u8g.setFont(u8g_font_unifont);
  // graphic commands to redraw the complete screen should be placed here  
 u8g.drawBitmapP ( 32 , 0 , 2 , 16 , bitmap_s); 
 u8g.drawBitmapP ( 49 , 0 , 2 , 16 , bitmap_y );
 u8g.drawBitmapP ( 66 , 0 , 2 , 16 , bitmap_d); 
 u8g.drawBitmapP ( 83 , 0 , 2 , 16 , bitmap_z );
}
void setup() {
  // put your setup code here, to run once:
  
}

void loop() {
  // put your main code here, to run repeatedly:
  char str1[32];
  char str2[32];
  int chk = DHT11.read(DHT11PIN);
  delay(200);
  if(chk==DHTLIB_OK)
  {
    sprintf(str1,"Humi:%d (%%)     ",(int)DHT11.humidity);
    sprintf(str2,"Temp:%d (oC)    ",(int)DHT11.temperature);
    }
  u8g.firstPage();  
  do {       
      draw();      
      u8g.drawStr(0, 56,str1);
      u8g.drawStr(0, 36,str2);
  } while( u8g.nextPage() );
  
  // rebuild the picture after some delay
  delay(500);
}
